// pages/health/health.js
var app = getApp()

var searchdata;

Page({


  /**
   * 页面的初始数据
   */
  data: {
    foodlists: [],
    recipes: []
  },
 
  loadSearchData: function () {
    var searchUrl = app.globalData.searchUrl
    console.log('searchUrl:' + searchUrl);
    var that = this;
    wx.request({
      url: searchUrl,
      data: {
        accss_token: app.accss_token,
        client_id: app.client_id,
        nonce: app.nonce,
        sign: app.sign,
        timestamp: app.timestamp
      },
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('code:  ' + res.statusCode);
        if (res.statusCode == 200) {
          searchdata = res.data;
          var foods = res.data.result.foods;
          that.setData({
            foodlists: foods
          })
        } else {
        }
      },
      fail: function (err) {
        console.log(err)
      }
    }
    )
  },

  toLoadBloodGlucose: function () {
    var searchUrl = app.globalData.bloodGlucoseUrl
    console.log('searchUrl:' + searchUrl);
    var that = this;
    wx.request({
      url: searchUrl,
      data: {
        accss_token: app.accss_token,
        client_id: app.client_id,
        nonce: app.nonce,
        sign: app.sign,
        timestamp: app.timestamp
      },
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('code:  ' + res.statusCode);
        if (res.statusCode == 200) {
          searchdata = res.data;
          var foods = res.data.result.foods;
          that.setData({
            foodlists: foods
          })
        } else {
        }
      },
      fail: function (err) {
        console.log(err)
      }
    }
    )
  },


  toSearchResult: function (e) {
    console.log('-------------click', e);
    wx.navigateTo({
      url: '../../pages/search/result/result?key="123"&name="ptt"',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toLoadBloodGlucose()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}) 